﻿//-----------------------------------------------------------------------
// <copyright file="XmlNodeBase.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Xml
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml;
    using System.Xml.Serialization;

    /// <summary>
    /// Represents a single node in the CXML document.
    /// </summary>
    [SerializableAttribute()]
    [XmlType(Namespace = "http://schemas.microsoft.com/collection/metadata/2009")]
    public class XmlNodeBase
    {
        /// <summary>
        /// Collection used to store any other XML element;
        /// </summary>
        private Collection<XmlElement> anyOtherElements;

        /// <summary>
        /// Collection used to stoe any other attributes.
        /// </summary>
        private AttributeCollection anyOtherAttributes;

        /// <summary>
        /// Initializes a new instance of the <see cref="XmlNodeBase"/> class.
        /// </summary>
        public XmlNodeBase()
        {
            this.anyOtherAttributes = new AttributeCollection();
            this.anyOtherElements = new Collection<XmlElement>();
        }

        /// <summary>
        /// Gets the namespace prefix.
        /// </summary>
        /// <value>The namespace prefix of the pivot collection node.</value>
        public static string NamespacePrefix 
        { 
            get 
            { 
                return "p"; 
            } 
        }

        /// <summary>
        /// Gets the name space URI.
        /// </summary>
        /// <value>The name space URI of the pivot collection node.</value>
        public static Uri NamespaceUri 
        { 
            get 
            {
                return new Uri("http://schemas.microsoft.com/livelabs/pivot/collection/2009");
            } 
        }

        /// <summary>
        /// Gets or sets the extension.
        /// </summary>
        /// <value>The extension of the pivot collection node.</value>
        public XmlElement Extension { get; set; }

        /// <summary>
        /// Gets any other XML Element.
        /// </summary>
        /// <value>Any of the pivot collection node.</value>
        [XmlAnyElement()]
        public Collection<XmlElement> AnyOtherElements 
        {
            get
            {
                return this.anyOtherElements;
            }
        }

        /// <summary>
        /// Gets any other attributes.
        /// </summary>
        /// <value>Any other attributes of the XML node base.</value>
        [XmlAnyAttribute()]
        public AttributeCollection AnyOtherAttributes 
        {
            get
            {
                return this.anyOtherAttributes;
            }
        }

        /// <summary>
        /// Adds the attribute.
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="attributeValue">The attribute value.</param>
        public void AddAttribute(string attributeName, string attributeValue)
        {
            this.AnyOtherAttributes.AddAttribute(NamespacePrefix, attributeName, attributeValue, NamespaceUri);
        }
    }
}
